package com.material.web.controller.factory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.material.common.utils.SecurityUtils;
import com.material.factory.params.FactoryReceivingPlanAdd;
import com.material.factory.params.FactoryReceivingPlanQuery;
import com.material.factory.vo.FactoryReceivingPlanListVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.AjaxResult;
import com.material.common.enums.BusinessType;
import com.material.factory.domain.FactoryReceivingPlan;
import com.material.factory.service.IFactoryReceivingPlanService;
import com.material.common.utils.poi.ExcelUtil;
import com.material.common.core.page.TableDataInfo;

/**
 * 工厂收货计划Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/factory/plan")
public class FactoryReceivingPlanController extends BaseController
{
    @Autowired
    private IFactoryReceivingPlanService factoryReceivingPlanService;

    /**
     * 查询工厂收货计划列表
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(FactoryReceivingPlanQuery factoryReceivingPlan)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            factoryReceivingPlan.setFactoryId(bizId);
        }
        startPage();
        List<FactoryReceivingPlanListVo> list = factoryReceivingPlanService.selectFactoryReceivingPlanPageList(factoryReceivingPlan);
        return getDataTable(list);
    }

    /**
     * 导出工厂收货计划列表
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:export')")
    @Log(title = "工厂收货计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FactoryReceivingPlan factoryReceivingPlan)
    {
        List<FactoryReceivingPlan> list = factoryReceivingPlanService.selectFactoryReceivingPlanList(factoryReceivingPlan);
        ExcelUtil<FactoryReceivingPlan> util = new ExcelUtil<FactoryReceivingPlan>(FactoryReceivingPlan.class);
        util.exportExcel(response, list, "工厂收货计划数据");
    }

    /**
     * 获取工厂收货计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(factoryReceivingPlanService.selectFactoryReceivingPlanById(id));
    }

    /**
     * 新增工厂收货计划
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:add')")
    @Log(title = "工厂收货计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FactoryReceivingPlanAdd factoryReceivingPlan)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            factoryReceivingPlan.setFactoryId(bizId);
        }
        return toAjax(factoryReceivingPlanService.batchInsertFactoryReceivingPlan(factoryReceivingPlan));
    }

    /**
     * 修改工厂收货计划
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:edit')")
    @Log(title = "工厂收货计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FactoryReceivingPlan factoryReceivingPlan)
    {
        return toAjax(factoryReceivingPlanService.updateFactoryReceivingPlan(factoryReceivingPlan));
    }

    /**
     * 删除工厂收货计划
     */
    @PreAuthorize("@ss.hasPermi('factory:plan:remove')")
    @Log(title = "工厂收货计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(factoryReceivingPlanService.deleteFactoryReceivingPlanByIds(ids));
    }
}
